package petstore.web.servlet.order;
import com.alibaba.fastjson.JSON;
import petstore.domain.Log;
import petstore.persistence.LogDaoImpl;
import petstore.persistence.user.User;
import petstore.persistence.user.UserDAOImpl;
import com.alibaba.fastjson.JSON;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.text.SimpleDateFormat;
@WebServlet("/check")
public class checSevlet extends HttpServlet {
    private int uid;
    private String username;//用户名
    private String password;//密码
    boolean result;
    User user;//用户类

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.username = req.getParameter("username");//从提交上来的form中获取用户名
        this.password = req.getParameter("password");//从提交上来的form中获取密码

        //判断用户名、密码是否正确合法的逻辑
        //如果合法，查询是否存在该用户
        UserDAOImpl userDAO = new UserDAOImpl();
        user = userDAO.FindUserByUsernameAndPassword(username, password);//userDAO查找用户，返回一个user类
        if(user == null) result = false;
        else result = true;
        String json = JSON.toJSONString(result);
        //System.out.println(json);//转换为json
        resp.setContentType("text/Json");
        resp.setCharacterEncoding("UTF-8");
        resp.getWriter().print(json);

        //判断用户名密码是否合法
    }
}
